import React, { useEffect, useState } from 'react'
import Item from './Item'
import PubSub from 'pubsub-js'

export default function Header() {
  const [searchList, setSearchList] = useState({ isInit: true, isSearch: false, data: [] })

  //订阅Header
  useEffect(() => {
    PubSub.subscribe("github", (_, data) => {
      setSearchList(data);
    })
  }, [])

  return (
    <div className="row">
      {
        searchList.isInit ? <h1>请求搜索用户</h1> :
          searchList.isSearch ? <h1>搜索中...</h1> :
            searchList.data.map(item => {
              return <Item key={item.id} {...item} />
            })
      }
    </div>
  )
}
